package com.zjh.common.result;

import com.zjh.common.constants.ResultConstants;

import java.io.Serializable;

/**
 * @author OZY
 * @Description:
 * @date 2016/6/4 11:49
 */
public class Result<T> implements Serializable {

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回数据载体
     */
    private T data;

    public Result() {

    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public Result error() {
        code = ResultConstants.RESUTLT_CODE_ERROR;
        message = ResultConstants.RESUTLT_MESSAGE_ERROR;
        return this;
    }


    public Result error(String message) {
        code = ResultConstants.RESUTLT_CODE_ERROR;
        this.message = message;
        return this;
    }

    public Result error(Integer code, String message) {
        this.code = code;
        this.message = message;
        return this;
    }


    public Result success() {
        code = ResultConstants.RESUTLT_CODE_SUCCESS;
        message = ResultConstants.RESUTLT_MESSAGE_SUCCESS;
        return this;
    }


    public Result success(String message) {
        code = ResultConstants.RESUTLT_CODE_SUCCESS;
        this.message = message;
        return this;
    }
}
